package com.jiang.daily.Q2264;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/01/08 14:02
 */
class Solution {
    public String largestGoodInteger(String num) {
        int len = num.length();
        if (len < 3) return "";
        char[] arr = num.toCharArray();
        int sonLen = 1; // 子字符串长度
        char maxHigh = ' '; //最大优质整数值
        for (int i = 1; i < len; i++) {
            if (arr[i] == arr[i - 1]) {
                if (++sonLen == 3 && arr[i] > maxHigh) {
                    maxHigh = arr[i];
                }
            } else {
                sonLen = 1;
            }
        }
        return maxHigh == ' ' ? "" : String.valueOf(maxHigh).repeat(3);
    }
}
